package com.example.administrator.myretrofitdemo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import com.example.administrator.myretrofitdemo.Entry.Index;
import com.example.administrator.myretrofitdemo.Entry.LoginBean;
import com.example.administrator.myretrofitdemo.http.HttpMethods;
import com.example.administrator.myretrofitdemo.subscribers.ProgressSubscriber;
import com.example.administrator.myretrofitdemo.subscribers.SubscriberOnNextListener;

import java.util.List;

public class MainActivity extends AppCompatActivity {

    private SubscriberOnNextListener getTopMovieOnNext;
    private TextView mViewById;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getTopMovieOnNext = new SubscriberOnNextListener<LoginBean>() {

            @Override
            public void onNext(LoginBean loginBean) {
                mViewById.setText(loginBean.toString());
            }

            @Override
            public void onError() {

            }
        };

        getTopMovieOnNext = new SubscriberOnNextListener<List<Index>>() {


            @Override
            public void onNext(List<Index> indices) {

            }

            @Override
            public void onError() {

            }
        };


        mViewById = (TextView) findViewById(R.id.result_TV);
        findViewById(R.id.click_me_BN).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
        //登录
        HttpMethods.getInstance(MainActivity.this).loginIn(new ProgressSubscriber(getTopMovieOnNext, MainActivity.this));
            }
        });
        findViewById(R.id.btn_index).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //登录
                HttpMethods.getInstance(MainActivity.this).index(new ProgressSubscriber(getTopMovieOnNext, MainActivity.this));
            }
        });

    }
}
